<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="pl.org.waff.*" %>
<jsp:useBean id="loginform" class="pl.org.waff.example.LoginForm" scope="request" />
<jsp:useBean id="sitenavigator" class="pl.org.waff.DefaultNavigator" scope="application" />
<jsp:useBean id="applicationprefix" class="java.lang.String" scope="application" />
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="<%=applicationprefix%>/resources/homestyle.css" />
    <title>Waff demo</title>
    <jsp:include page="components/analytics.jsp"/>
</head>
<body>
    <div id="wrapper">
        <div id="header"><jsp:include page="components/header.jsp"/></div>
        <div id="menu"><jsp:include page="components/menu.jsp"/></div>
        <div id="breadcrumb"><jsp:include page="components/breadcrumb.jsp"/></div>
        <div id="main">
            <div id="content">
                <h1>Log in</h1>
                <% User user = (User) request.getSession().getAttribute("waffuser");
                    boolean userIsLogged = user.isLoggedIn();
                    if (!userIsLogged && loginform.getErrorCode() > -1) {
                        user = WaffServlet.getUserManager().getUser(loginform.getLogin(), loginform.getPassword());
                        userIsLogged = user.isLoggedIn();
                        request.getSession().setAttribute("waffuser", user);
                    }
                    if (!userIsLogged) {
                        String pathPrefixIfMobile = (String) request.getSession().getAttribute(WaffServlet.PATH_PREFIX_ATTRIBUTE_NAME);
                %>
                <form action=<%=sitenavigator.getAbsolutePath("/loginform.login.do", pathPrefixIfMobile)%>>
                    <table>
                        <tr><td>Login:</td><td><input type="text" name="login"/></td></tr>
                        <tr><td>Password:</td><td><input type="password" name="password"/></td></tr>
                        <tr><td colspan="2"><button type="submit">OK</button></td></tr>
                    </table>
                </form>
                <%                } else {
                        out.print("Welcome " + user.getName() + "!");
                    }
                %>                    
            </div>
        </div>
        <div id="footer"><jsp:include page="components/footer.jsp"/></div>
    </div>
</body>  
</html>